package com.health.manage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.health.manage.pojo.dto.UserDto;
import com.health.manage.pojo.entity.User;
import com.health.manage.service.IUserService;
import com.health.manage.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 * @Description: 用户管理控制器
 * @author: user
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户管理")
@CrossOrigin
public class UserController extends BaseController{

    @Autowired
    private IUserService userService;

    @PostMapping("list")
    @ApiOperation(value = "获取列表数据", notes = "", httpMethod = "POST")
    public ResponseResult<Page<User>> list(@RequestBody UserDto userDto){

        Page<User> dataList = this.userService.getPageData(userDto);
        return ResponseResult.success(dataList);
    }

    @GetMapping("one")
    @ApiOperation(value = "查询用户数据", notes = "", httpMethod = "POST")
    public ResponseResult<User> one(Long id){

        User data = this.userService.getById(id);
        return ResponseResult.success(data);
    }

    @PostMapping("add")
    @ApiOperation(value = "添加数据", notes = "", httpMethod = "POST")
    public ResponseResult<Boolean> add(@RequestBody User user){

        Boolean result = this.userService.addData(user);
        return ResponseResult.success(result);
    }

    @PostMapping("update")
    @ApiOperation(value = "更新数据", notes = "", httpMethod = "POST")
    public ResponseResult<Boolean> update(@RequestBody User user){

        Boolean result = this.userService.updateData(user);
        return ResponseResult.success(result);
    }

    @DeleteMapping("{id}")
    @ApiOperation(value = "删除数据", notes = "", httpMethod = "DELETE")
    public ResponseResult<Boolean> delete(@PathVariable Long id){

        Boolean result = this.userService.deleteData(id);
        return ResponseResult.success(result);
    }



}
